package com.mlm.mlmapp;

import android.app.Activity;
import android.app.Application;
import android.os.Bundle;
import android.os.StrictMode;

import com.androidquery.AQuery;
import com.androidquery.callback.AjaxCallback;
import com.androidquery.util.AQUtility;

import java.util.HashMap;
import java.util.Map;

import im.fir.sdk.FIR;

/**
 * Created by Administrator on 2016/4/13 0013.
 */
public class BaseApplication extends Application implements Application.ActivityLifecycleCallbacks {


    public static final String MOBILE_AGENT = "Mozilla/5.0 (Linux; U; Android 2.2) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533";
    public static Map<Class,Activity> map=new HashMap<>();

    @Override
    public void onCreate() {
        FIR.init(this);
        if (AQuery.SDK_INT >= 9) {
            AQUtility.debug("enable strict mode!");
            StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
                    .detectAll()
                    .penaltyLog()
                    .build());

            StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
                    .detectAll()
                    .penaltyLog()
                    //.penaltyDeath()
                    .build());
        }

        super.onCreate();
        this.registerActivityLifecycleCallbacks(this);
        AjaxCallback.setNetworkLimit(25);

    }


    @Override
    public void onLowMemory() {
//        BitmapAjaxCallback.clearCache();
        super.onLowMemory();
    }

    @Override
    public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
        map.put(activity.getClass(),activity);
    }

    @Override
    public void onActivityStarted(Activity activity) {

    }

    @Override
    public void onActivityResumed(Activity activity) {

    }

    @Override
    public void onActivityPaused(Activity activity) {

    }

    @Override
    public void onActivityStopped(Activity activity) {

    }

    @Override
    public void onActivitySaveInstanceState(Activity activity, Bundle outState) {

    }

    @Override
    public void onActivityDestroyed(Activity activity) {
        map.remove(activity.getClass());
    }
}
